<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
    问题: number类型能表达的最大数值有限, 如果存储计算一个超过number最大值的超大数值如何处理?
    解决: 使用ES2020规范中的BigInt
    使用:
        BigInt(string | number | boolean)
        数值n
    注意: 不能将BigInt与其它类型进行运算, 只能与BigInt值进行算术运算
    */
    let count = Number.MAX_VALUE
    let count2 = count + 2
    console.log(count, count2)
    console.log(count2-count) // 0  超过最大值后, 再增加也只能是最大值

    let count3 = BigInt(count)
    // let count5 = count3 + 3  // error 不能将BigInt与其它类型进行运算
    let count4 = count3 + 3n
    console.log(count3, count4)
    console.log(count4-count3) // 3n

    console.log(typeof count3) // bigint


    /* 
    MDN文档: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/BigInt
    */
  </script>
</body>
</html>